package com.huawei.fastengine.fastview.download.download;

import android.os.Handler;
import android.os.Message;
import android.util.Log;
import android.widget.Toast;
import com.huawei.fastengine.R;
import com.huawei.fastengine.fastview.Config;
import com.huawei.fastengine.fastview.download.install.InstallProcess;
import com.huawei.fastengine.fastview.download.install.ManagerTask;
import com.huawei.fastengine.fastview.download.utils.ActivityUtil;
import com.huawei.fastengine.fastview.download.utils.log.FastViewLogUtils;
import java.text.NumberFormat;

class HiappDownloadActivity$DownloadAppHandler extends Handler {
    final /* synthetic */ HiappDownloadActivity this$0;

    private HiappDownloadActivity$DownloadAppHandler(HiappDownloadActivity hiappDownloadActivity) {
        this.this$0 = hiappDownloadActivity;
    }

    private void dealDownload(Message message) {
        switch (message.what) {
            case 1:
                if (message.arg2 == 0) {
                    FastViewLogUtils.e("msg.arg2==0  ");
                    return;
                }
                int i = (int) ((((double) message.arg1) / ((double) message.arg2)) * 100.0d);
                long j = (long) message.arg1;
                if (i > 0) {
                    HiappDownloadActivity.access$900(this.this$0).setProgress(i);
                    float progress = ((float) HiappDownloadActivity.access$900(this.this$0).getProgress()) / ((float) HiappDownloadActivity.access$900(this.this$0).getMax());
                    int i2 = (int) (100.0f * progress);
                    CharSequence format = NumberFormat.getPercentInstance().format((double) progress);
                    FastViewLogUtils.e("download,", "" + i + "/" + j + "/" + progress + "/" + i2);
                    HiappDownloadActivity.access$1000(this.this$0).setText(format);
                    return;
                }
                return;
            case 3:
                HiappDownloadActivity.access$900(this.this$0).setProgress(100);
                HiappDownloadActivity.access$1000(this.this$0).setText(NumberFormat.getPercentInstance().format(1.0d));
                Log.i("HiappDownloadActivity", "has downloaded");
                InstallProcess.installProcess(this.this$0.getApplicationContext(), new ManagerTask(Config.FASTAPP_PACKAGE_NAME, message.getData().getString("path")));
                return;
            case 4:
                if (!ActivityUtil.isActivityDestroyed(this.this$0)) {
                    Toast.makeText(this.this$0, this.this$0.getString(R.string.fastapp_dl_install_failed), 0).show();
                    try {
                        HiappDownloadActivity.access$1200(this.this$0).dismiss();
                    } catch (IllegalArgumentException e) {
                        Log.e("HiappDownloadActivity", "dlProgressDialog dismiss IllegalArgumentException");
                    }
                    this.this$0.finish();
                    Log.e("HiappDownloadActivity", "download activity on download failed.");
                    return;
                }
                return;
            default:
                FastViewLogUtils.e("HiappDownloadActivity", "Unkonw message " + message.what);
                return;
        }
    }

    public void handleMessage(Message message) {
        dealDownload(message);
    }
}
